/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dmc;

import com.gaib.dmc.AODEsrReviewer;
import com.gaib.dmc.Reviewer;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

/**
 *
 * @author Asus
 */
public class DMC {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws FileNotFoundException, IOException {
        // TODO code application logic here
        String session = "";
        long timeNow = System.currentTimeMillis();
        Reviewer reviewer = new AODEsrReviewer();
        String[] baris = Baca("transact_train.txt");
        int n_beda = 0;
        double buffer = 0;
        String jawaban = "";
        for(int i =1; i < baris.length; i++) {
            String[] kalimat = BacaBaris(baris[i]);
            //System.out.println("Data - " + i);
            //System.out.println(kalimat[0]);
            /*for (String w : kalimat) {
                System.out.println(w);
            }*/
            if(!session.equals("") && !session.equals(kalimat[0])) {
                //reviewer.submitOutcome(jawaban);
                session = kalimat[0];
            } else {
                session = kalimat[0];
            }
            jawaban = kalimat[kalimat.length-1];
            
            double hasil = reviewer.submitTransaction(kalimat);
            //System.out.println(kalimat[kalimat.length-1] + " : " +hasil);
            
            if((kalimat[kalimat.length-1].equals("n") && hasil > 0.5) || (kalimat[kalimat.length-1].equals("y") && hasil < 0.5))
                n_beda++;
            buffer += Math.abs((kalimat[kalimat.length-1].equals("y") ? 1 : 0) - hasil);
        }
        System.out.println("n Beda:" + n_beda);
        System.out.println("buffer : " + buffer);
        System.out.println(System.currentTimeMillis()-timeNow);
    }
    
    public static String[] Baca (String path) throws FileNotFoundException, IOException {
        BufferedReader br = new BufferedReader(new FileReader(path));
        String everything = " ";
        try {
            StringBuilder sb = new StringBuilder();
            String line = br.readLine();

            while (line != null) {
                sb.append(line);
                sb.append("\n");
                line = br.readLine();
            }
            everything = sb.toString();
        } finally {
            br.close();
        }
        String[] w = everything.split("\n");
        return (w);
    }
    
    public static String[] BacaBaris (String wtemp) throws FileNotFoundException, IOException {
        String[] hasil = wtemp.split("");
        
        int size = 1;
        for (String ww : hasil) {
            if ((ww.equals("|"))) {
                size++;
            }
        }
        
        String[] hasil2 = new String[size];
        for (int j=0; j<hasil2.length; j++) {
            hasil2[j] = "";
        }
        
        int i=0;
        for (String ww : hasil) {
            if ((ww.equals("|")))
                i++;
            else
                hasil2[i] = hasil2[i] + ww;
        }
        
        return (hasil2);
    }
}
